package com.supor.aiot.websocket;

/**
 * ---------------------------------------------------------------- <br>
 * Copyright (C) 2014-2021, by het, ShenZhen, All rights reserved.  <br>
 * ---------------------------------------------------------------- <br>
 * <p>
 * 描述: ErrorMessage <br>
 * 作者: lei <br>
 * 日期: 2021/9/22 <br>
 */
public class ErrorMessage {

    private Exception exception;
    private int mCode;
    private String mMsg;
    private boolean remote;

    public final static int UNKNOWN_CODE = -1;
    public final static int TOKEN_ERROR = 1;

    public ErrorMessage() {
    }

    public ErrorMessage(Exception exception) {
        this.exception = exception;
    }

    public ErrorMessage(int code, String msg) {
        this.mCode = code;
        this.mMsg = msg;
    }

    public ErrorMessage(int code, String msg, boolean remote) {
        this.mCode = code;
        this.mMsg = msg;
        this.remote = remote;
    }

    public int getCode() {
        return mCode;
    }

    public void setCode(int code) {
        this.mCode = code;
    }

    public String getMsg() {
        return mMsg;
    }

    public void setMsg(String msg) {
        this.mMsg = msg;
    }

    public int getValue() {
        return this.mCode;
    }

    public String getMessage() {
        return this.mMsg;
    }

    public void setRemote(boolean remote) {
        this.remote = remote;
    }

    public boolean isRemote() {
        return remote;
    }

    public void setException(Exception exception) {
        this.exception = exception;
    }

    public Exception getException() {
        return exception;
    }

    public static ErrorMessage valueOf(int code) {
        ErrorMessage errorMessage = new ErrorMessage();
        errorMessage.setCode(code);
        switch (code) {
            case UNKNOWN_CODE:
                errorMessage.setMsg("未知错误");
                break;
            case TOKEN_ERROR:
                errorMessage.setMsg("token错误");
                break;
            default:
                errorMessage.setMsg("未知错误");
                break;
        }
        return errorMessage;
    }

    public static ErrorMessage valueOf(int code, String msg) {
        return new ErrorMessage(code, msg);
    }
}
